package com.test.canal;

import com.alibaba.otter.canal.protocol.FlatMessage;
import com.cayden.componets.canal.handle.CanalContext;
import com.cayden.componets.canal.handle.CanalHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author cayden
 * @date 2021-10-19 15:00
 */
@Component
@Slf4j
public class BuildDatabaseBuildUserCanalHandle extends CanalHandle {

    @Override
    public void updateHandleInfo(CanalContext canalContext) {
        FlatMessage flatMessage = canalContext.getFlatMessage();
        List<Map<String, String>> old = flatMessage.getOld();
        List<Map<String, String>> data = flatMessage.getData();

        for (Map<String, String> olds : old) {
            for (String o : olds.keySet()) {
                log.info("old:" +o+" "+ olds.get(o));
            }
        }

        for (Map<String, String> datas : data) {
            for (String o : datas.keySet()) {
                log.info("new:" +o+" "+ datas.get(o));
            }
        }

    }

    @Override
    public void insertHandleInfo(CanalContext canalContext) {
        FlatMessage flatMessage = canalContext.getFlatMessage();
        List<Map<String, String>> data = flatMessage.getData();
        for (Map<String, String> datas : data) {
            for (String o : datas.keySet()) {
                log.info("new:" +o+" "+ datas.get(o));
            }
        }
    }

    @Override
    public void deleteHandleInfo(CanalContext canalContext) {

    }
}
